package com.atguigu.gmall.task.scheduled;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@EnableScheduling
@Component
@Slf4j
public class ScheduledTask {
    @Autowired
    private RabbitService rabbitService;

    //每天凌晨1点发送消息   每隔10秒发一次
    @Scheduled(cron = "0/10 * * * * ?")
    public void task1(){
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"山重水复疑无路");
    }
    //  秒杀结束之后，发送消息将数据从缓存中删除！每天18点后
    @Scheduled(cron = "* * 18 * * ?")
    public void task2(){
        //  远程调用service-activity 查询数据，并将数据放入缓存！
        //  发送一个消息！
        this.rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_18,"柳暗花明又一村.");
    }
}
